Skip to content

[JExtract] Bridge closures with UnsafeRawBufferPointer parameter #282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2025

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jun 23, 2025

First step to bridging closures with conversions.

E.g.

public func withBuffer(body: (UnsafeRawBufferPointer) -> Void)

is lowered to:

void c_withBuffer(void (*body)(const void *, ptrdiff_t));

then translated to:

public static class withBuffer {
    @FunctionalInterface
    public interface body {
      void apply(java.lang.foreign.MemorySegment _0);
    }
}
public static void withBuffer(withBuffer.body body);

First step to bridging closures with conversions.
)
}

func lowerClosureParameter(
Copy link
Member Author

@rintaro rintaro Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unfortunate that we now have another lower/translate function for closure parameters (in addition to regular parameters, and results), and probably we'd add more for closure result conversions. But this works for now, and we can consolidate them after we implement more types, and find common logics among them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but still managable... agreed on converging later if we find ways to do so 👍


closure.statements = CodeBlockItemListSyntax {
body.map {
$0.with(\.leadingTrivia, [.newlines(1), .spaces(4)])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didn't know about .newlines, that's nice

@ktoso
Copy link
Collaborator

ktoso commented Jun 24, 2025

Happy to merge this now and I'll finish up landing the commands and test infra fixes today on top of this 👍 Should have not impact really on that ongoing work.

@rintaro rintaro merged commit 9145d71 into swiftlang:main Jun 24, 2025
17 checks passed
@rintaro rintaro deleted the jextract-closure-withbuffer branch June 24, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants